<template>
  <div class="head-container">
    <!-- 搜索 -->
    <el-input v-model="query.contractCode" clearable placeholder="合同编号" style="width: 200px;" class="filter-item" @keyup.enter.native="toQuery" />
    <el-input v-model="query.contractName" clearable placeholder="合同名称" style="width: 200px;" class="filter-item" @keyup.enter.native="toQuery" />
    <el-input v-model="query.serviceproviderName" clearable placeholder="所属服务商" style="width: 200px;" class="filter-item" @keyup.enter.native="toQuery" />
    <el-select v-model="query.contractItemId" clearable placeholder="合同类型" class="filter-item" @change="indexSelect($event)">
      <el-option v-for="(item,index) in contTypeItem" :key="index" :label="item.label" :value="item.id" />
    </el-select>
    <el-button class="filter-item" size="mini" type="success" icon="el-icon-search" @click="toQuery">搜索</el-button>
    <!-- 新增 -->
    <div style="display: inline-block;margin: 0px 2px;">
      <el-button
        v-permission="['ADMIN','TSERVICEPROVIDERCONTRACT_ALL','TSERVICEPROVIDERCONTRACT_CREATE']"
        class="filter-item"
        size="mini"
        type="primary"
        icon="el-icon-plus"
        @click="$refs.form.dialog = true"
      >
        新增
      </el-button>
      <eForm ref="form" :is-add="true" :is-view="false" />
    </div>
  </div>
</template>

<script>
import eForm from './form'
import request from '@/utils/request'
export default {
  components: { eForm },
  props: {
    query: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      queryTypeOptions: [
        { key: 'contractCode', display_name: '合同编号' },
        { key: 'contractName', display_name: '合同名称' },
        { key: 'serviceproviderName', display_name: '服务商' },
        { key: 'contractItemName', display_name: '合同类型' }
      ],
      contTypeItem: []
    }
  },
  mounted: function() {
    this.byNameinfo('合同类型')
  },
  methods: {
    toQuery() {
      this.$parent.page = 0
      this.$parent.init()
    },
    byNameinfo(name) {
      this.byName(name).then(res => {
        this.bydictId(res.id).then(resobject => {
          this.contTypeItem = resobject
        })
      })
    },
    // 获取id值
    byName(name) {
      return request({
        url: 'api/dict/byName/' + name,
        method: 'get'
      })
    },
    // 获取id值
    bydictId(id) {
      return request({
        url: 'api/dictDetail/findByDeptId/' + id,
        method: 'get'
      })
    }

  }
}
</script>
